import path from "node:path";
import fs from "node:fs";
import { exec } from "../electron/main/util/sudo-prompt";
import * as readline from "node:readline";

// const __dirname = path.dirname(fileURLToPath(import.meta.url));
// const linkCmd = path.resolve(__dirname, "link-dir.cmd");

// const proc = child_process.spawn(linkCmd, ["C:\\Dev\\NodeJS", "C:\\Dev\\Denv\\NodeJS/v20.16.0"], { windowsHide: true, stdio: "inherit" });
// proc.stdout?.on("data", data => {
//   console.log("spawn =>", data.toString().trimEnd());
// });
// proc.stderr?.on("data", data => {
//   console.error("error => ", data.toString().trimEnd());
// });
//
// proc.on("exit", () => console.log("exit"));

const sourceDir = "C:\\Dev\\Denv\\NodeJS\\v20.16.0";
const linkDir = "C:\\Dev\\NodeJS-c";
if (fs.existsSync(linkDir)) {
  fs.unlinkSync(linkDir);
}

exec(
  `mklink /J "${linkDir}" "${sourceDir}"`,
  { name: "Denv" },
  (err, stdout, stderr) => {
    console.log(err, stdout, stderr);
  },
  "create-current-nodejs-symlink",
);

// fs.symlinkSync(sourceDir, linkDir);
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
rl.question("Press any key to continue...", () => {
  process.exit(0);
});
